<?php
//页码函数
function pagenavi() {
    global $wp_query, $wp_rewrite;
    $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
    $pagination = array(
        'base' => @add_query_arg('paged','%#%'),
        'format' => '',
        'total' => $wp_query->max_num_pages,
        'current' => $current,
        'show_all' => false,
		'end_size'=>'1',   
        'mid_size'=>'12',
        'type' => 'plain',
        'prev_next' => false
    );
    if( $wp_rewrite->using_permalinks() )
        $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg('s',get_pagenum_link(1) ) ) . 'page/%#%/', 'paged');
    if( !empty($wp_query->query_vars['s']) )
        $pagination['add_args'] = array('s'=>get_query_var('s'));
	previous_posts_link('上一页','');
    echo paginate_links($pagination);
	next_posts_link('下一页','');
	if( $pagination['total']>1 ){
	}
}

//获取缩略图
function get_post_img( $id = null,$width="150",$height="100") {
	if( $id ){
		$post = get_post($id);
		$post_id = $id;
	}else{
		global $post;
		$post_id = $post->ID;
	}
	
	if(get_post_meta($post_id,'_post_pic',true)&&(get_post_meta($post_id,'_post_pic',true)!='')){
		return get_post_meta($post_id,'_post_pic',true);
	}else{
		$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
	
		if( !empty( $matches[1][0] ) ){
			return $matches[1][0];
		}else{
			return '';
		}
	}
}

//计算字符
if ( !function_exists('mb_strlen') ) {
	function mb_strlen ($text, $encode) {
		if ($encode=='UTF-8') {
			return preg_match_all('%(?:
					  [\x09\x0A\x0D\x20-\x7E]           # ASCII
					| [\xC2-\xDF][\x80-\xBF]            # non-overlong 2-byte
					|  \xE0[\xA0-\xBF][\x80-\xBF]       # excluding overlongs
					| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
					|  \xED[\x80-\x9F][\x80-\xBF]       # excluding surrogates
					|  \xF0[\x90-\xBF][\x80-\xBF]{2}    # planes 1-3
					| [\xF1-\xF3][\x80-\xBF]{3}         # planes 4-15
					|  \xF4[\x80-\x8F][\x80-\xBF]{2}    # plane 16
					)%xs',$text,$out);
		}else{
			return strlen($text);
		}
	}
}

/*截取字符串函数*/
if (!function_exists('mb_substr')) {
    function mb_substr($str, $start, $len = '', $encoding="UTF-8"){
        $limit = strlen($str);
        for ($s = 0; $start > 0;--$start) {// found the real start
            if ($s >= $limit)
                break;
            if ($str[$s] <= "\x7F")
                ++$s;
            else {
                ++$s; // skip length
                while ($str[$s] >= "\x80" && $str[$s] <= "\xBF")
                    ++$s;
            }
        }
       if ($len == '')
            return substr($str, $s);
        else
            for ($e = $s; $len > 0; --$len) {//found the real end
                if ($e >= $limit)
                    break;
                if ($str[$e] <= "\x7F")
                    ++$e;
                else {
                    ++$e;//skip length
                    while ($str[$e] >= "\x80" && $str[$e] <= "\xBF" && $e < $limit)
                        ++$e;
                }
            }
        return substr($str, $s, $e - $s);
    }
}

//获取浏览数
function getPostViews($postID){
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
        return "0";
    }
    return $count;
}
//设置浏览数
function setPostViews($postID) {
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}


function addhttp($url) {
    if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
        $url = "http://" . $url;
    }
    return $url;
}

function is_valid_int( $int ) {
    $int = isset( $int ) ? intval( $int ) : 0;
    return $int;
}
/**********编辑文章的连接*****************/
function user_edit_post_link( $url, $post_id ) {
    if ( is_admin() ) {
        return $url;
    }

    $override = wpuf_get_option( 'override_editlink', 'yes' );
    if ( $override == 'yes' ) {
        $url = '';
        if ( wpuf_get_option( 'enable_post_edit' ) == 'yes' ) {
            $edit_page = (int) wpuf_get_option( 'edit_page_id' );
            $url = get_permalink( $edit_page );

            $url = wp_nonce_url( $url . '?pid=' . $post_id, 'wpuf_edit' );
        }
    }

    return $url;
}

//add_filter( 'get_edit_post_link', 'user_edit_post_link', 10, 2 );


/******格式化错误*********/
function user_error_msg( $error_msg ) {
    $msg_string = '';
    foreach ($error_msg as $value) {
        if ( !empty( $value ) ) {
            $msg_string = $msg_string . '<div class="error">' . $msg_string = $value . '</div>';
        }
    }
    return $msg_string;
}
/*********整理标签**********/
function user_clean_tags( $string ) {
    $string = preg_replace( '/\s*,\s*/', ',', rtrim( trim( $string ), ' ,' ) );
    return $string;
}
/**************邮件通知管理员有来稿**************/
function user_notify_post_mail( $user, $post_id ) {
    $blogname = get_bloginfo( 'name' );
    $to = get_bloginfo( 'admin_email' );
    $permalink = get_permalink( $post_id );

    $headers = sprintf( "来自: %s <%s>\r\n", $blogname, $to );
    $subject = sprintf( '[%s] 有新投稿', $blogname );

    $msg = sprintf( '%s 上有人提交了新文章', $blogname ) . "\r\n\r\n";
    $msg .= sprintf( '作者 : %s', $user->display_name ) . "\r\n";
    $msg .= sprintf( '作者Email : %s', $user->user_email ) . "\r\n";
    $msg .= sprintf( '标题: %s', get_the_title( $post_id ) ) . "\r\n";
    $msg .= sprintf( '文章地址 : %s', $permalink ) . "\r\n";
    $msg .= sprintf( '编辑链接 : %s', admin_url( 'post.php?action=edit&post=' . $post_id ) ) . "\r\n";
	
    wp_mail( $to, $subject, $msg, $headers );
}

/******将文件作为附件上传****************/
function user_upload_attachment( $post_id ) {
    if ( !isset( $_FILES['wpuf_post_attachments'] ) ) {
        return false;
    }

    $fields = (int) wpuf_get_option( 'attachment_num' ); //设置选项，附件数目

    for ($i = 0; $i < $fields; $i++) {
        $file_name = basename( $_FILES['wpuf_post_attachments']['name'][$i] );

        if ( $file_name ) {
            if ( $file_name ) {
                $upload = array(
                    'name' => $_FILES['wpuf_post_attachments']['name'][$i],
                    'type' => $_FILES['wpuf_post_attachments']['type'][$i],
                    'tmp_name' => $_FILES['wpuf_post_attachments']['tmp_name'][$i],
                    'error' => $_FILES['wpuf_post_attachments']['error'][$i],
                    'size' => $_FILES['wpuf_post_attachments']['size'][$i]
                );

                wpuf_upload_file( $upload ); //上传文件
            }
        }
    }
}

/***********上传文件函数*******************/
function user_upload_file( $upload_data ) {
	//上传
    $uploaded_file = wp_handle_upload( $upload_data, array('test_form' => false) );

    // If the wp_handle_upload call returned a local path for the image
    if ( isset( $uploaded_file['file'] ) ) {
        $file_loc = $uploaded_file['file'];
        $file_name = basename( $upload_data['name'] );
        $file_type = wp_check_filetype( $file_name );

        $attachment = array(
            'post_mime_type' => $file_type['type'],
            'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $file_name ) ),
            'post_content' => '',
            'post_status' => 'inherit'
        );
		//插入附件
        $attach_id = wp_insert_attachment( $attachment, $file_loc );
		//附件信息
        $attach_data = wp_generate_attachment_metadata( $attach_id, $file_loc );
		//插入附件信息
        wp_update_attachment_metadata( $attach_id, $attach_data );

        return $attach_id;
    }

    return false;
}

/***********检查提交的附件是否有错误*************/
function user_check_upload() {
    $errors = array();
    $mime = get_allowed_mime_types(); //允许上传的文件格式

    $size_limit = (int) (wpuf_get_option( 'attachment_max_size' ) * 1024); //设置选项-允许上传的最大文件大小
    $fields = (int) wpuf_get_option( 'attachment_num' ); //设置选项，允许的文件数量

    for ($i = 0; $i < $fields; $i++) {
        $tmp_name = basename( $_FILES['wpuf_post_attachments']['tmp_name'][$i] );
        $file_name = basename( $_FILES['wpuf_post_attachments']['name'][$i] );

        //if file is uploaded
        if ( $file_name ) {
            $attach_type = wp_check_filetype( $file_name );
            $attach_size = $_FILES['wpuf_post_attachments']['size'][$i];

            //检查文件大小
            if ( $attach_size > $size_limit ) {
                $errors[] = __( "Attachment file is too big" );
            }

            //检查文件格式
            if ( !in_array( $attach_type['type'], $mime ) ) {
                $errors[] = __( "Invalid attachment file type" );
            }
        } // if $filename
    } // endfor

    return $errors;
}

function user_get_avatar($uid, $w = 25, $h = 25){
	$av = get_user_meta($uid, 'avatar', true);
	if ($av) {
		return $av;
	}else{
		return bloginfo('template_directory').'/images/default-user.jpg';
	}
}

function uctheme_wp_comment( $comment, $args, $depth ) {
	$GLOBALS['comment'] = $comment;
	switch ( $comment->comment_type ) :
		case '' :
	?>
	<div class="perComment"  id="li-comment-<?php comment_ID(); ?>">
		<div class="avatarImgBox">
			<?php
			if($comment->user_id){
				$user_info = get_userdata($comment->user_id);
			?>
				<a  target="_blank" href="<?php  echo site_url().'/user-profile/'.$user_info->user_login; ?>">
				<?php echo get_avatar( $comment->user_id, 40 ); ?>
				</a>
			<?php }else{
				echo get_avatar( $comment, 40,'',$comment->comment_author );
			}
			?>
		</div>
		<div class="commentRight">
				<div class="commentName"><?php echo get_comment_author_link(); ?></div>
				<div class="commentTime"><?php	printf('%1$s %2$s', get_comment_date('m.d'),  get_comment_time('g:i') ); ?>&nbsp;<?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?></div>
				<div class="clear"></div>
				<div class="nrBox"><?php comment_text(); ?></div>
		</div>
		<div class="clear"></div>
		<div class="line"></div>
	<?php
			break;
		case 'pingback'  :
		case 'trackback' :
			break;
	endswitch;
}

/*************获取文章的附件************/
function user_get_attachments( $post_id ) {
    $att_list = array();

    $args = array(
        'post_type' => 'attachment',
        'numberposts' => -1,
        'post_status' => null,
        'post_parent' => $post_id,
        'order' => 'ASC',
        'orderby' => 'menu_order'
    );

    $attachments = get_posts( $args );

    foreach ($attachments as $attachment) {
        $att_list[] = array(
            'id' => $attachment->ID,
            'title' => $attachment->post_title,
            'url' => wp_get_attachment_url( $attachment->ID ),
            'mime' => $attachment->post_mime_type
        );
    }

    return $att_list;
}

/***********编辑文章时编辑附件********/
function user_edit_attachment( $post_id ) {
    $attach = wpfu_get_attachments( $post_id );

    if ( $attach ) {
        $count = 1;
        foreach ($attach as $a) {

            echo 'Attachment ' . $count . ': <a href="' . $a['url'] . '">' . $a['title'] . '</a>';
            echo "<form name=\"wpuf_edit_attachment\" id=\"wpuf_edit_attachment_{$post_id}\" action=\"\" method=\"POST\">";
            echo "<input type=\"hidden\" name=\"attach_id\" value=\"{$a['id']}\" />";
            echo "<input type=\"hidden\" name=\"action\" value=\"del\" />";
            wp_nonce_field( 'wpuf_attach_del' );
            echo '<input class="wpuf_attachment_delete" type="submit" name="wpuf_attachment_delete" value="delete" onclick="return confirm(\'Are you sure to delete this attachment?\');">';
            echo "</form>";
            echo "<br>";
            $count++;
        }
    }
}

function user_attachment_fields( $edit = false, $post_id = false ) {
    if ( wpuf_get_option( 'allow_attachment' ) == 'yes' ) {
        $fields = (int) wpuf_get_option( 'attachment_num' );

        if ( $edit && $post_id ) {
            $fields = abs( $fields - count( wpfu_get_attachments( $post_id ) ) );
        }

        for ($i = 0; $i < $fields; $i++) {
            ?>

            <li>
                <label for="wpuf_post_attachments">
                    Attachment <?php echo $i + 1; ?>:
                </label>
                <input type="file" name="wpuf_post_attachments[]">
                <div class="clear"></div>
            </li>

            <?php
        }
    }
}
/*********用户评论******/
function user_comments_list( $comment, $args, $depth ){
	$GLOBALS['comment'] = $comment;
	switch ( $comment->comment_type ) :
		case '' :
	?>
	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
		<a href="<?php echo get_permalink($comment->comment_post_ID);?>">
		<?php comment_text(); ?>
		</a>
	<?php
			break;
		case 'pingback'  :
		case 'trackback' :
			break;
	endswitch;
}
/*********获取用户************/
function wpuf_list_users() {
    if ( function_exists( 'get_users' ) ) {
        $users = get_users();
    } else {
        ////wp 3.1 fallback
        $users = get_users_of_blog();
    }

    $list = array();

    if ( $users ) {
        foreach ($users as $user) {
            $list[$user->ID] = $user->display_name;
        }
    }

    return $list;
}

/*******判断字符串某位置后是否出现特定字符串********/
function wpuf_starts_with( $string, $starts ) {

    $flag = strncmp( $string, $starts, strlen( $starts ) );

    if ( $flag == 0 ) {
        return true;
    } else {
        return false;
    }
}

/*************判断文件是否为图片************/
function user_is_file_image( $file, $mime ) {
    $ext = preg_match( '/\.([^.]+)$/', $file, $matches ) ? strtolower( $matches[1] ) : false;

    $image_exts = array('jpg', 'jpeg', 'gif', 'png');

    if ( 'image/' == substr( $mime, 0, 6 ) || $ext && 'import' == $mime && in_array( $ext, $image_exts ) ) {
        return true;
    }

    return false;
}
/**********用户菜单**************/
function user_get_users_links(){
	global $wpdb,$wp_rewrite,$wp_query,$current_user;
	get_currentuserinfo();
	if( isset($wp_query->query_vars['my_second_page']) && $wp_query->query_vars['my_second_page'] !='' )
		$current_page = $wp_query->query_vars['my_second_page'];
	else $current_page = 'home';
	?>
	<div class="page-info">
	<div class="main-container">
	<div id="breadcrumbs">
		<?php //dimox_breadcrumbs(); ?>
	</div>
	</div>
	<div class="uc_tabs">
	<ul>
		<li <?php	if($current_page == 'home') echo "class='active'"; ?>>
			<a href="<?php echo smzdm_my_account_link(); ?>">个人信息</a>
		</li>   
        		
          <li <?php	if($current_page == 'my-jifen') echo "class='active'"; ?>>
			<a href="<?php echo smzdm_my_account_link(); ?>/my-jifen/">我的积分</a>
		 </li>  
         
		<li <?php	if($current_page == 'my-settings') echo "class='active'"; ?>>
			<a href="<?php echo smzdm_my_account_link(); ?>/my-settings/">编辑资料</a>
		</li>
		<li <?php	if($current_page == 'my-posts') {echo "class='active'";}?>>
			<a href="<?php echo smzdm_my_account_link(); ?>/my-posts/">已发布文章</a>
		</li>
		<li <?php	if($current_page == 'my-comments') {echo "class='active'";}?>>
			<a href="<?php echo smzdm_my_account_link(); ?>/my-comments/">我的评论</a>
		</li>
		<li <?php	if($current_page == 'my-collects') {echo "class='active'";}?>>
			<a href="<?php echo smzdm_my_account_link(); ?>/my-collects/">我的收藏</a>
		</li>
		<li <?php	if($current_page == 'post-new') {echo "class='active last'";} else {echo "class='last'";} ?>>
			<a href="<?php bloginfo('url'); ?>/tougao">发表文章</a>
			<div class="last"></div>
		</li>
	</ul>
	</div>
	</div>
	<div class='clear'></div>
<?php 
}
/***********页码函数********/
function emm_paginate($args = null) {
	          $defaults = array(
		        'page' => null, 'pages' => null, 
		        'range' => 2, 'gap' => 1, 'anchor' => 1,
		        'before' => '<div class="emm-paginate">', 'after' => '</div>',
		        'title' => __(''),
		        'nextpage' => __('&raquo;'), 'previouspage' => __('&laquo'),
	          'echo' => 1
);
$r = wp_parse_args($args, $defaults);
	          extract($r, EXTR_SKIP);
	          if (!$page && !$pages) {
		        global $wp_query;
		        $page = get_query_var('paged');
		        $page = !empty($page) ? intval($page) : 1;
		        $posts_per_page = intval(get_query_var('posts_per_page'));
		        $pages = intval(ceil($wp_query->found_posts / $posts_per_page));
}
$output = "";
	          if ($pages > 1) {	
		        $output .= "$before<span class='emm-title'>$title</span>";
		        $ellipsis = "<span class='emm-gap'></span>";
		        if ($page > 1 && !empty($previouspage)) {
		    	  $output .= "<a href='" . get_pagenum_link($page - 1) . "' class='emm-prev'>$previouspage</a>";
}
            $min_links = $range * 2 + 1;
		        $block_min = min($page - $range, $pages - $min_links);
		        $block_high = max($page + $range, $min_links);
		        $left_gap = (($block_min - $anchor - $gap) > 0) ? true : false;
		        $right_gap = (($block_high + $anchor + $gap) < $pages) ? true : false;
if ($left_gap && !$right_gap) {
			      $output .= sprintf('%s%s%s', 
			    	emm_paginate_loop(1, $anchor), 
			    	$ellipsis, 
				    emm_paginate_loop($block_min, $pages, $page)
);
}
else if ($left_gap && $right_gap) {
			     $output .= sprintf('%s%s%s%s%s', 
				   emm_paginate_loop(1, $anchor), 
				   $ellipsis, 
				   emm_paginate_loop($block_min, $block_high, $page), 
				   $ellipsis, 
				   emm_paginate_loop(($pages - $anchor + 1), $pages)
);
}
else if ($right_gap && !$left_gap) {
			     $output .= sprintf('%s%s%s', 
			   	 emm_paginate_loop(1, $block_high, $page),
				   $ellipsis,
				   emm_paginate_loop(($pages - $anchor + 1), $pages)
);
}
else {
			     $output .= emm_paginate_loop(1, $pages, $page);
}
if ($page < $pages && !empty($nextpage)) {
			     $output .= "<a href='" . get_pagenum_link($page + 1) . "' class='emm-next'>$nextpage</a>";
}
		       $output .= $after;
}
if ($echo) {
		       echo $output;
}
return $output;
}

function add_fav($post_id,$user_id){
	global $wpdb;
	$user_id = (int)$user_id;
	$post_id = (int)$post_id;
	$check= "select * from ".$wpdb->prefix."userpost_fav where post='$post_id' and user='$user_id'";
	$coo = $wpdb->get_results($check);
	if(!count($coo) > 0){
		$tm = time();
		$s = "insert into ".$wpdb->prefix."userpost_fav (user,post,vote_date) values('$user_id','$post_id','$tm')";
		$wpdb->query($s);	 
		echo "y";	
	}else{
		echo "h";	
	} 
}

function get_user_fav_posts($uid){
	global $wpdb;
	$uid = (int)$uid;
	$sql = "select count(*) from ".$wpdb->prefix."userpost_fav where user='$uid'";
	$coo = $wpdb->get_results($sql);
}


/*********获取用户收藏的文章总数**********/
function get_user_fav_count($user_id){
	global $wpdb;
	$user_id = (int)$user_id;
	$sql = "select count(*) from ".$wpdb->prefix."userpost_fav where user='$user_id'";
	$coo = $wpdb->get_var($sql);
	if($coo)
	return $coo;
	else
	return 0;
}
/**********获取收藏某文章的人数*********/
function get_post_fav_count($post_id){
	global $wpdb;
	$post_id = (int)$post_id;
	$sql = "select count(*) from ".$wpdb->prefix."userpost_fav where post='$post_id'";
	$coo = $wpdb->get_var($sql);
	if($coo)
	return $coo;
	else
	return 0;
}
/*************获取用户的评论总数*******************/
function get_user_comments_count($user_id){
	global $wpdb;
	$user_id = (int)$user_id;
	$sql = "select count(*) from {$wpdb->comments} where user_id='$user_id' and comment_approved = 1";
	$coo = $wpdb->get_var($sql);
	if($coo)
	return $coo;
	else
	return 0;
}



/*******menu walker***********/
class SH_Last_Walker extends Walker_Nav_Menu{
   function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {

        $id_field = $this->db_fields['id'];
       if( isset($children_elements[$element->$id_field]) ) { 
            $classes = empty( $element->classes ) ? array() : (array) $element->classes;
            $classes[] = 'haschildren';
            $element->classes =$classes;
       }
        if( 0 == $depth ){
			$classes = empty( $element->classes ) ? array() : (array) $element->classes;
            $classes[] = 'level1';
            $element->classes =$classes;
		}
		if( 1 == $depth ){
			$classes = empty( $element->classes ) ? array() : (array) $element->classes;
            $classes[] = 'level2';
            $element->classes =$classes;
		}
		if( 2 == $depth ){
			$classes = empty( $element->classes ) ? array() : (array) $element->classes;
            $classes[] = 'level3';
            $element->classes =$classes;
		}
        $parent_id_field = $this->db_fields['parent'];      
        $parent_id = $element->$parent_id_field;
        $siblings = $children_elements[ $parent_id ] ;
        if( ! is_array($siblings) )
            return parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
        $last_child = array_pop($siblings);
        $id_field = $this->db_fields['id'];
        if( $element->$id_field == $last_child->$id_field ){
            $classes = empty( $element->classes ) ? array() : (array) $element->classes;
            $classes[] = 'last';
            $element->classes =$classes;
        }
        return parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
    }
}



add_action('generate_rewrite_rules', 'ashu_rewrite_rules' );
function ashu_rewrite_rules( $wp_rewrite ){
    $new_rules = array(
        'go/?([0-9]{1,})/?$' => 'index.php?my_custom_page=go&pid='.$wp_rewrite->preg_index(1),
    );
    $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}

add_action('query_vars', 'ashu_add_query_vars');
function ashu_add_query_vars($public_query_vars){
    $public_query_vars[] = 'my_custom_page';
	$public_query_vars[] = 'pid';
    return $public_query_vars;
}

add_action("template_redirect", 'ashu_template_redirect');
function ashu_template_redirect(){
    global $wp;
    global $wp_query, $wp_rewrite;
    $reditect_page =  $wp_query->query_vars['my_custom_page'];
    if ($reditect_page == "go"){
        include(TEMPLATEPATH.'/go.php');
        die();
    }
}

add_action( 'load-themes.php', 'frosty_flush_rewrite_rules' );
function frosty_flush_rewrite_rules() {
    global $pagenow, $wp_rewrite;
    if ( 'themes.php' == $pagenow && isset( $_GET['activated'] ) )
        $wp_rewrite->flush_rules();
}


function custom_dashboard_help() {
 echo "<p>
 <li>欢迎您选择优畅出品的SMZDM主题</li>
 <li>本主题是专门为淘宝客打造的一款实用性很强的主题，此版本为商业版</li>
 <li>在使用过程中，如果遇到问题，请及时和我联系</li>
 <li>Email: satiling@163.com&nbsp;&nbsp;&nbsp;QQ: 1583310276</li></ol></p>";    
}
function example_add_dashboard_widgets() {
    wp_add_dashboard_widget('custom_help_widget', '欢迎使用优畅主题', 'custom_dashboard_help');
}
add_action('wp_dashboard_setup', 'example_add_dashboard_widgets' );

/* 修改后台底部左侧版权 */
function modify_footer_admin () {
	echo 'Design By <a href="http://www.uctheme.com" target="_blank">优畅主题设计</a>.';
	echo 'Powered By <a href="http://WordPress.org" target="_blank">WordPress</a>.';
}
add_filter('admin_footer_text', 'modify_footer_admin');


/* 移除后台底部右侧版权 */ 
function modify_footer_version() {
	return '<a href="http://www.uctheme.com" target="_blank">欢迎访优畅主题- http://www.uctheme.com</a>.';
} 
add_filter( 'update_footer', 'modify_footer_version', 9999);

//移除后台顶部左上角图标
function annointed_admin_bar_remove() {
        global $wp_admin_bar;
        /* Remove their stuff */
        $wp_admin_bar->remove_menu('wp-logo');
}
add_action('wp_before_admin_bar_render', 'annointed_admin_bar_remove', 0);
 

// 用户注册成功后自动登录，并跳转到指定页面  
function auto_login_new_user( $user_id ) {
  wp_set_current_user($user_id);
  wp_set_auth_cookie($user_id);
  
  // 这里设置的是跳转到首页，要换成其他页面
  // 可以将home_url()改成你指定的URL
  // 如 wp_redirect( 'http://www.baidu.com' );
  $url = home_url().'/my-account';
  echo "<script>location.href='$url';</script>";
  exit;
}
add_action( 'user_register', 'auto_login_new_user' );

?>